package cn.tedu.epidemic.webapi.config;

import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;

/**
 * 用于检查controller请求方法中封装好或未封装的请求参数
 */
@Configuration
public class ValidationConfiguration {

    @Bean
    public javax.validation.Validator validator(){
        return Validation.byProvider(HibernateValidator.class)
                .configure()  //开始配置
                .failFast(true) //配置快速失败
                .buildValidatorFactory() //构建Validator工厂
                .getValidator(); //从Validator中获取Validator对象
    }
}
